package main

import (
	"flag"
	"log"
	"os"

	gopher_lua_lib "github.com/u2takey/gopher-lua-lib"
	libs "github.com/vadv/gopher-lua-libs"
	lua "github.com/yuin/gopher-lua"
)

var (
	exec = flag.String("execute", os.Args[1], "execute lua script")
)

func main() {
	flag.Parse()
	state := lua.NewState()
	defer state.Close()
	libs.Preload(state)
	gopher_lua_lib.InstallAll(state)
	// my lib
	state.PreloadModule("km", LuaModuleKMLoader)
	if *exec != `` {
		if err := state.DoFile(*exec); err != nil {
			log.Print("[ERROR] Error executing file: ", err)
		}
	} else {
		log.Println("Target file was not given!")
		os.Exit(0)
	}
}
